<?php

/**
 * This is the model class for table "tbl_logs".
 *
 * The followings are the available columns in table 'tbl_logs':
 * @property integer $operID
 * @property string $optTable
 * @property integer $bookID
 * @property string $name
 * @property string $operate
 * @property string $date
 * @property string $descript
 */
class Logs extends CActiveRecord
{
	/**
	 * 定义日志的常量
	 */
	const BOOK_CREATE='新建书目';
	const BOOK_UPDATE='更新书目';
	const BOOK_DEL='删除书目';
	
	const READER_CREATE='新建读者';
	const READER_UPDATE='更新读者信息';
	const READER_DEL='删除读者信息';
	
	const BBR_BROWE='借出图书';
	const BBR_RETURN='收到还书';
	
	const OPT_TAB_BOOK='书目'; 
	const OPT_TAB_READER='读者';
	const OPT_TAB_BBR = '借阅';
	
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Logs the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_logs';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('bookID', 'numerical', 'integerOnly'=>true),
			array('optTable', 'length', 'max'=>15),
			array('name', 'length', 'max'=>10),
			array('operate', 'length', 'max'=>20),
			array('descript', 'length', 'max'=>255),
			array('date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('operID, optTable, bookID, name, operate, date, descript', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'operID' => '记录号',
			'optTable' => '操作对象',
			'bookID' => '对象编号',
			'name' => '操作员',
			'operate' => '操作类型',
			'date' => '时间',
			'descript' => '描述',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('operID',$this->operID);
		$criteria->compare('optTable',$this->optTable,true);
		$criteria->compare('bookID',$this->bookID);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('operate',$this->operate,true);
		$criteria->compare('date',$this->date,true);
		$criteria->compare('descript',$this->descript,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}